﻿using System.Collections.Generic;

public class DataBattleMgr
{
    public string ChallengeUid;
    private Dictionary<string, DataBattlePlayer> _userid2data = new Dictionary<string, DataBattlePlayer>();
    public Dictionary<string, DataBattlePlayer> userid2data
    {
        get { return _userid2data; }
    }
    private int _index = 0;
    public const int MaxPlayerNum = 10;
    public void AddDataPlayer(member_info vPerson)
    {
        var player = new DataBattlePlayer(vPerson.uid, vPerson.name, vPerson.card_type, vPerson.support_type);
        player.SetIndex(_index);
        _userid2data[vPerson.uid] = player;
        _index++;
    }

    public int GetShowIndex(int vIndex)
    {
        var myselfData = this.GetDataPlayer(DataPlayer.Instance.userId);
        vIndex -= myselfData.GetIndex();
        if (vIndex < 0)
            vIndex += MaxPlayerNum;
        return vIndex;
    }

    public DataBattlePlayer GetDataPlayer(int vIndex)
    {
        foreach (var item in _userid2data.Values)
        {
            if (item.GetIndex() == vIndex)
                return item;
        }
        return null;
    }

    public DataBattlePlayer GetDataPlayer(string userId)
    {
        DataBattlePlayer player;
        _userid2data.TryGetValue(userId, out player);
        return player;
    }

    public int GetDataPlayerCount()
    {
        return _userid2data.Count;
    }
}
